#include <iostream>
#include <vector>
#include "RMQ.h"

using namespace std;

void main()
{
	int N, M;
//	cout << "Enter size of array: ";
	cin >> N;
	vector<double> vect( N );

//	cout << "Enter array:\n";
	for( int i = 0; i < N; i++ )
		cin >> vect[i];
	RMQ rmq( vect );
//	cout << endl;
///	rmq.Print();

//	cout << "Enter number of queries: ";
	cin >> M;
	vector<double> result( M );

//	cout << "Enter queries:\n";
	for( int i = 0; i < M; i++ )
	{
		int a, b;
		cin >> a;
		cin >> b;
		if( a < 0 || a >= N || b > N || a >= b )
		{
			cout << "Incorrect input\n";
			return;
		}
//		cout << rmq.GetMin( a, b ) << endl;
		result[i] = rmq.GetMin( a, b );
	}

	for( int i = 0; i < M; i++ )
		cout << result[i] << ' ';
	cout << endl;
}